﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="demo.aspx.cs" Inherits="demo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>demo</title>
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
</head>
<body>
</body>
    <script type="text/javascript">
        var token = "";
        //获取到token的值保存到数据库(进入页面就执行)
        $(document).ready(function() { 
            $.ajax({
                type: "GET",
                async: false,
                data: {},
                url: "https://receive.symacnc.cn/v20/Verification/authorize?grant_type=clientc_credential&appid=11E96964685A7AAAB96598039B073FBC&secret=EV72BU9X2ZPV35XBR60HCWXBOUFRKTGMDJJAB3QZ&comid=11E8D1D6-636B-84CE-8CF1-00163E008027",
                dataType: "json",
                success: function (ret) {
                    token = ret.access_token
                    $.ajax({
                        type: "GET",
                        async: false,
                        data: {token:token,method:'savetoken' },
                        url: "GetDeviceInfo.ashx",
                        dataType: "json",
                        success: function (ret) {

                        },
                        error: function (t) {
                            alert(t.data);
                        }
                    })
                }
            })
        });
        //获取（19台）2018-01-01到2019-05-07保存到数据库
        $(document).ready(function () { 
            var sid;
            var between;
            var t;
            var tt;
            var urls = "https://receive.symacnc.cn/v20/Dept/getBettenHourStatuInfo?grant_type=clientc_credential&access_token=";
             $.ajax({
                type: "GET",
                async: false,
                data:{method:'querytoken'},
                url: "demo.ashx",
                dataType: "json",
                success: function (ret) {
                    var tokens = ret.token;
                    var sysid = ret.sysids;
                    var name = ret.names;
                    for (var i = 0; i < sysid.length; i++) {
                             sid = sysid[i].sysid;
                        for (var j = 0; j < name.length; j++) {
                            between = name[j].name;
                        $.ajax({
                            type: "GET",
                            async: false,
                            data: { "sysid": sid,"between":between},
                            url: "" + urls + tokens + "",
                            dataType: "json",
                            success: function (ret) {
                                var a_data = {};
                                a_data["sysid"] = sid;
                                a_data["code"] = ret.code;
                                a_data["msg"] = ret.msg;
                                a_data["dayseconds"] = ret.dayseconds;
                                a_data["date"] = ret.date;
                                a_data["endtime"] = ret.endtime;
                                a_data["runstatu"] = ret.runstatu;
                                a_data["alarmstatu"] = ret.alarmstatu;
                                a_data["systemtime"] = ret.systemtime;
                                var data = ret.data;
                                var b_data = {};
                                for (var i in data) {
                                    var a = data[i];
                                    b_data["name"] = i;
                                    b_data["alarmstatu1"] = a.alarmstatu;
                                    b_data["runstatu1"] = a.runstatu;
                                    tt = b_data;
                                    //将数组解析为json格式传入后台
                                    var datas = JSON.stringify(tt);
                                    $.ajax({
                                            type: "GET",
                                            async: false,
                                            data: { datas: datas, method:'savedata'},
                                            url: "demo.ashx",
                                            dataType: "json",
                                            success: function (ret) {
                                        
                                            }
                                        })
                                }
                                t = a_data;
                                //将数组解析为json格式传入后台
                                var deviceinfo = JSON.stringify(t);
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    data: { deviceinfo: deviceinfo, method:'savedevice'},
                                    url: "demo.ashx",
                                    dataType: "json",
                                    success: function (ret) {
                                        if (i == 18) {
                                        }
                                    }
                                })
                            }
                        })
                      }
                    }
                 }
               
            })
        });
    </script>
</html>
